package com.ytc.service;

import com.ytc.dto.CarDto;
import com.ytc.dto.CarTypeDto;
import com.ytc.entity.CarBrand;
import com.ytc.entity.CarType;
import com.ytc.mapper.CarBrandMapper;
import com.ytc.mapper.CarMapper;
import com.ytc.mapper.CarTypeMapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.ParameterResolutionDelegate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CarService implements CarServiceApi{

    @Autowired
    private CarMapper carMapper;
    @Autowired
    private CarBrandMapper carBrandMapper;
    @Autowired
    private CarTypeMapper carTypeMapper;


    @RequestMapping("queryCarList1")
    @ResponseBody
    public Map<String,Object> queryCarList(@RequestBody CarDto carDto) {
        Map<String,Object> map = new HashMap<>();
        try {
            List<CarDto> carList = carMapper.queryCarList(carDto);
            System.out.println(carList.toString()+"111111111111111111111111111");
            map.put("success",true);
            map.put("data",carList);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("查询车辆列表失败");
        }
        return map;
    }

    @RequestMapping("getBrandnameList1")
    @ResponseBody
    public Map<String, Object> getBrandnameList() {
        Map<String,Object> map = new HashMap<>();
        try {
            List<CarBrand> nameList = carBrandMapper.getBrandnameList();
            map.put("success",true);
            map.put("data",nameList);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("查询车辆品牌失败");
        }
        return map;
    }

    @RequestMapping("togetType1")
    @ResponseBody
    public Map<String, Object> getTypeList(@RequestParam("bandid") Integer bandid) {
        Map<String,Object> map = new HashMap<>();
        System.out.println(bandid+"222222222222222222222222222");
        try {
            List<CarTypeDto> nameList = carTypeMapper.getTypeList(bandid);
            map.put("success",true);
            map.put("data",nameList);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("查询类型失败");
        }
        return map;
    }

    @RequestMapping("getType11")
    @ResponseBody
    public Map<String, Object> toType(Integer typeid) {
        Map<String,Object> map = new HashMap<>();
        try {
            List<CarTypeDto> nameList = carMapper.getTypeList(typeid);
            map.put("success",true);
            map.put("data",nameList);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("查询类型失败");
        }
        return map;
    }


/*    @RequestMapping("getCarNameList1")
    @ResponseBody
    public Map<String, Object> getCarNameList() {
        Map<String,Object> map = new HashMap<>();
        try {
            List<CarBrand> nameList = carBrandMapper.getCarNameList();
            map.put("success",true);
            map.put("data",nameList);
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException("查询车辆品牌失败");
        }
        return map;
    }*/
}
